/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package Tools;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Ivan
 */
/**
 * This abstract class contains base methods and field and describes signature
 * of abstract methods which should be overridden in the class of successor which
 * implements functions of CMD.
 *
 * @author Ivan
 */
public abstract class ACommand {

    protected IExtraThreadFactory extraThread;
    public final String commandName;
    protected StringBuffer stringPrintResult;
    protected List<String> validParameters;

    protected ACommand(String commandName, IExtraThreadFactory extraThread) {
        this.extraThread = extraThread;
        this.commandName = commandName;
        validParameters = new ArrayList<String>(0);
        stringPrintResult = new StringBuffer(0);
    }

    protected ACommand(String commandName) {
        this.commandName = commandName;
        validParameters = new ArrayList<String>(0);
        stringPrintResult = new StringBuffer(0);

    }

    /**
     * Method which implements action of command
     * @param parameters
     * @param key
     * @return
     * @throws Exception
     */
    public abstract Object action(String key) throws Exception;

    /**
     * This method used for checks of specified parameters and returns those of them that is valid
     * @param parameters
     * @return
     * @throws Exception
     */
    public abstract void setParameters(List<String> parameters) throws Exception;

    public abstract void isValidKey(String key) throws Exception;

    public String getPrintResult() {
        String s = new String();
        if (stringPrintResult != null) {

            s = stringPrintResult.toString();
            stringPrintResult = new StringBuffer();
            validParameters.clear();
        }
        return s;
    }

    protected void setPrintResult(StringBuffer stringPrintResult) {
        this.stringPrintResult = stringPrintResult;
    }
}
